<?php


namespace app\user\controller;

use think\Db;
use think\facade\Request;

/**
 * Class Schedule 待办事项
 * @package app\user\controller
 */
class Schedule extends LoggingBase
{
    #region 今日需要联系客户
    /**
     * 界面：今日需要联系客户列表
     */
    public function ContactClientList()
    {
        //我的直接下级员工
        $SuperiorID = $this->m_User->ID;
        $StaffData = Db::table('user')->field('ID,Name,Nick')->where("IsDeleted='0' AND SuperiorID='$SuperiorID'")->select();
        $this->assign('StaffData', $StaffData);
        $this->assign('Today', date('Y-m-d'));
        $Css = array(
            '<link href="/layui/css/layui.css" rel="stylesheet"/>'
        );
        return $this->mb_Display('今日需要联系客户', 'TodayContactClient','contact_client',$Css);
    }

    /**
     * 接口：今日需要联系客户列表
     */
    public function mb_ContactClientList()
    {
        $Page = Request::has('page') ? Request::param('page') : 1;
        $Limit = Request::has('limit') ? Request::param('limit') : 10;
        $Keyword = Request::has('Keyword') ? Request::param('Keyword') : '';
        $Date = date('Y-m-d');

        $Where = '';
        $Where .= " AND ((DATE_FORMAT(TimeCreated,'%Y-%m-%d')='$Date' AND DATE_FORMAT(Next,'%Y-%m-%d')!='$Date') OR  DATE_FORMAT(Next,'%Y-%m-%d')='$Date')";
        if ($Keyword != '') {
            $Where .= " AND (Name LIKE '%$Keyword%' OR Phone LIKE '%$Keyword%') ";
        }

        $UserID = $this->m_User->ID;
        $Count = Db::table('client')->where("IsDeleted='0' AND OwnerID='$UserID' AND OwnerType='1' $Where ")->count();
        $Data = Db::table('client')->where("IsDeleted='0' AND OwnerID='$UserID' AND OwnerType='1' $Where ")->page($Page, $Limit)->order('ID', 'DESC')->select();
        foreach ($Data as $Key => $Val) {
            if ($Val['Deal'] == 0) {
                $Data[$Key]['DealStatus'] = '<i class="icon-remove-circle" style="color: red"></i>未成交';
            } else {
                $Data[$Key]['DealStatus'] = '<i class="icon-ok-circle" style="color: green"></i>已成交';
            }
            $Data[$Key]['Source'] = $this->GetSourceName($Val['Source']);
            $Data[$Key]['IndustryName'] = $this->GetIndustryName($Val['Industry']);
            $Data[$Key]['LevelName'] = $this->GetLevelName($Val['Level']);
        }
        mb_OutMessage(ErrCode_Normal, '', $Data, $Count);
    }
    #endregion

    private function GetSourceName($Source)
    {
        $Name = '';
        switch ($Source) {
            case 1:
                $Name = '促销活动';
                break;
            case 2:
                $Name = '搜索引擎';
                break;
            case 3:
                $Name = '广告';
                break;
            case 4:
                $Name = '转介绍';
                break;
            case 5:
                $Name = '线上注册';
                break;
            case 6:
                $Name = '线上询价';
                break;
            case 7:
                $Name = '预约上门';
                break;
            case 8:
                $Name = '陌拜';
                break;
            case 9:
                $Name = '招商资源';
                break;
            case 10:
                $Name = '公司资源';
                break;
            case 11:
                $Name = '展会资源';
                break;
            case 12:
                $Name = '个人资源';
                break;
            case 13:
                $Name = '电话咨询';
                break;
            case 14:
                $Name = '邮件咨询';
                break;
            default:
                break;
        }
        return $Name;
    }

    private function GetIndustryName($Industry)
    {
        $Name = '';
        switch ($Industry) {
            case 1:
                $Name = 'IT/通信/电子/互联网';
                break;
            case 2:
                $Name = '金融业';
                break;
            case 3:
                $Name = '房产业';
                break;
            case 4:
                $Name = '商业服务';
                break;
            case 5:
                $Name = '贸易';
                break;
            case 6:
                $Name = '生产';
                break;
            case 7:
                $Name = '运输物品';
                break;
            case 8:
                $Name = '服务业';
                break;
            case 9:
                $Name = '文化传媒';
                break;
            case 10:
                $Name = '政府';
                break;
            case 11:
                $Name = '其他';
                break;
        }
        return $Name;
    }

    private function GetLevelName($Level)
    {
        $Name = 'A类（重点客户）';
        switch ($Level) {
            case 'B':
                $Name = 'B类（普遍客户）';
                break;
            case 'C':
                $Name = 'C类（非优先客户）';
                break;
        }
        return $Name;
    }

    private function GetSourceNum($Source)
    {
        $Name = 0;
        switch ($Source) {
            case '促销活动':
                $Name = 1;
                break;
            case '搜索引擎':
                $Name = 2;
                break;
            case '广告':
                $Name = 3;
                break;
            case '转介绍':
                $Name = 4;
                break;
            case '线上注册':
                $Name = 5;
                break;
            case '线上询价':
                $Name = 6;
                break;
            case '预约上门':
                $Name = 7;
                break;
            case '陌拜':
                $Name = 8;
                break;
            case '招商资源':
                $Name = 9;
                break;
            case '公司资源':
                $Name = 10;
                break;
            case '展会资源':
                $Name = 11;
                break;
            case '个人资源':
                $Name = 12;
                break;
            case '电话咨询':
                $Name = 13;
                break;
            case '邮件咨询':
                $Name = 14;
                break;
            default:
                break;
        }
        return $Name;
    }

    private function GetIndustryNum($Industry)
    {
        $Name = 0;
        switch ($Industry) {
            case 'IT/通信/电子/互联网':
                $Name = 1;
                break;
            case '金融业':
                $Name = 2;
                break;
            case '房产业':
                $Name = 3;
                break;
            case '商业服务':
                $Name = 4;
                break;
            case '贸易':
                $Name = 5;
                break;
            case '生产':
                $Name = 6;
                break;
            case '运输物品':
                $Name = 7;
                break;
            case '服务业':
                $Name = 8;
                break;
            case '文化传媒':
                $Name = 9;
                break;
            case '政府':
                $Name = 10;
                break;
            case '其他':
                $Name = 11;
                break;
        }
        return $Name;
    }

    private function GetLevelNum($Level)
    {
        $Name = 'B';
        switch ($Level) {
            case 'A类（重点客户）':
                $Name = 'A';
                break;
            case 'C类（非优先客户）':
                $Name = 'C';
                break;
        }
        return $Name;
    }
}